/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.controller;

import br.com.documentar.interfacee.InterfaceController;
import br.com.documentar.model.OpcaoDocumentoModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Santos
 */
public class OpcaoDocumentoController implements InterfaceController<br.com.documentar.model.OpcaoDocumentoModel> {

    private final br.com.documentar.DAO.OpcaoDocumentoDAO dao = new br.com.documentar.DAO.OpcaoDocumentoDAO();

    @Override
    public OpcaoDocumentoModel getModel() {
        return new br.com.documentar.model.OpcaoDocumentoModel();
    }

    @Override
    public DefaultTableModel insertTableModel(OpcaoDocumentoModel model) {
        model.getModelTable().setNumRows(0);
        for (br.com.documentar.model.OpcaoDocumentoModel p : dao.getDados(model)) {
            model.getModelTable().addRow(new Object[]{p.getCodigo(),
                p.getDocumento().getCodigo(), p.getValor(), p.getComportamento(), p.getAnexo()});
        }
        return model.getModelTable();
    }

    @Override
    public DefaultTableModel getDadosTableModel(OpcaoDocumentoModel model) {
        return insertTableModel(model);
    }

    @Override
    public boolean setDados(OpcaoDocumentoModel model) {
        return dao.setDados(model);
    }

    @Override
    public DefaultComboBoxModel getDadosComboBoxModel(OpcaoDocumentoModel model) {
        return insertComboBoxModel(model);
    }

    @Override
    public DefaultComboBoxModel insertComboBoxModel(OpcaoDocumentoModel model) {
        for (br.com.documentar.model.OpcaoDocumentoModel p : dao.getDados(model)) {
            //model.getModelComboBox().addElement(p.getCodigo() + " - " + p.getValor());
        }
        return model.getModelComboBox();
    }
}
